const app = getApp()
Page({
  data: {
    loading: true,
    icons: [],
    store: [],
  },
  //监听页面初次载入完成
  onShow: function () {
    var that = this;
    that.setData({
      loading: true,
    });
    this.getApiStroe();
  },
  //下拉刷新
  onPullDownRefresh: function () {
    var that = this;
    wx.showNavigationBarLoading();
    setTimeout(function () {
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    that.setData({
      loading: true,
      store: []
    });
    this.getApiStroe();
  },
  //获取店铺
  getApiStroe: function () {
    let that = this;
    if (that.data.loading) {
      app.api().Get('api/v1/allwin-store-union',function (result) {
        if (result.code == 200){
          that.setData({
            loading: false,
            store: result.data,
          });
        }else{
          that.setData({
            loading: false,
            store:[],
          });
        }
      })
    }
  },
  onClose(event) {
    let that = this;
    var id = event.currentTarget.id;
    wx.showModal({
      content: '确认要删除联盟商家吗?', showCancel: false, success: function (res){
        if (res.confirm) {
          app.api().Post('api/v1/allwin-store-editunion', { 'store_id': id }, function (result) {
            that.setData({
              loading: true
            })
            that.getApiStroe();
          })
        }
      }
    })
  }
});